package com.taotao.manage.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.dto.PageResult;
import com.taotao.common.dto.ResponseResult;
import com.taotao.content.service.ContentService;
import com.taotao.entity.Content;
import com.taotao.entity.Item;

/**  
 * @Title：ContentController.java   
 * @Description：
 * @Author：张朝阳
 * @Date：2019年7月8日 下午10:34:55   
 */

@Controller
@RequestMapping("/content")
public class ContentController {
	
	@Autowired
	private ContentService contentService;
	
	@RequestMapping("/save")
	@ResponseBody
	public ResponseResult saveContent(Content content) {
		try {
			contentService.addContent(content);
		}catch (Exception e) {
			return ResponseResult.error(e.getMessage());
		}
		return ResponseResult.ok();
	}
	
	@RequestMapping("query/list")
	@ResponseBody
	public PageResult<Content> getContentList(int page ,int rows,Long categoryId) {
		List<Content> contentList = contentService.getListByCategoryIdForPage(page, rows, categoryId);
		PageResult<Content> result = new PageResult<>();
		result.setRows(contentList);
		result.setTotal(contentList.size());
		return result;
	}
}
